package stud.aistar.mapper;

import org.apache.ibatis.annotations.Select;
import stud.aistar.vo.CountTimeVo;
import stud.aistar.vo.DoctorPatientVo;

import java.util.List;

/**
 * *
 *
 * @ClassName :wangyu
 * @Description:查询病人所有的挂号信息
 * @Author
 * @Date2019/10/2 12:45
 * @Version V1.0
 */
public interface DoctorPatientVoMapper {

    @Select("select pat.id,pat.patient_name,pat.patient_tel,pat.person_card,pat.patient_age,pat.patient_sex,pat.reg_status,pat.create_time,pat.doctor_id,doc.doc_name,sdept.sdept_name from reg_office pat JOIN doctor doc ON pat.doctor_id = doc.id JOIN second_department sdept ON doc.sdept_id = sdept.id JOIN time t on pat.time_id = t.id where reg_status <> 1 and reg_status <> 2 and doctor_id = #{dId} and date_format(t.start_times,'%Y-%m-%d')= date_format(now(),'%Y-%m-%d') ORDER BY create_time")
    List<DoctorPatientVo> findAll(Integer dId);

    @Select("select pat.patient_name,pat.patient_tel,pat.person_card,pat.patient_age,pat.patient_sex,pat.create_time,pat.doctor_id,doc.doc_name,sdept.sdept_name from reg_office pat JOIN doctor doc ON pat.doctor_id = doc.id JOIN second_department sdept ON doc.sdept_id = sdept.id where doctor_id = #{id}")
    List<DoctorPatientVo> findById(Integer id);

    @Select("select count(id) from reg_office")
    int findCount();

    @Select("select date_format(t.start_times,'%Y-%m-%d') years,count(date_format(t.start_times,'%Y-%m-%d')) counts from reg_office pat JOIN doctor doc ON pat.doctor_id = doc.id JOIN second_department sdept ON doc.sdept_id = sdept.id JOIN time t on pat.time_id = t.id where reg_status <> 1 and reg_status <> 2 and doctor_id = #{docId} GROUP BY years")
    List<CountTimeVo> findCountAndTime(Integer docId);

}
